<?php
class Wow_Armory_Core_Curl
{
    
    /**
     * Includes the curl object.
     * 
     * @var curl|object
     */
    protected $_cUrl = null;
    
    /**
     * Creates the object.
     * 
     * @return void
     */
    public function __construct()
    { }
    
    /**
     * Inits the curl class.
     * 
     * @return Wow_Armory_Core_Curl
     */
    public function init()
    {
        $this->_cUrl = curl_init();
        return $this;
    }
    
    /**
     * Sets the url.
     * 
     * @param  string $url
     * @return Wow_Armory_Core_Curl
     */
    public function setUrl($url)
    {
        if (!is_string($url)
            || empty($url)
        ) {
            throw new Wow_Armory_Exception('', 1015);
        }
        
        curl_setopt($this->_cUrl, CURLOPT_URL, $url);
        return $this;
    }
    
    /**
     * Sets the user agent.
     * 
     * @param  string $agent
     * @return Wow_Armory_Core_Curl
     */
    public function setUserAgent($agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12")
    {
        if (!is_string($agent)
            || empty($agent)
        ) {
            throw new Wow_Armory_Exception('', 1016);
        }
        
        curl_setopt(
            $this->_cUrl, 
            CURLOPT_USERAGENT, 
            $agent
        );
        return $this;
    }
    
    /**
     * Execute the curl method.
     * 
     * @return string
     */
    public function execute()
    {
        curl_setopt($this->_cUrl, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($this->_cUrl);
        curl_close($this->_cUrl);
        return $result;
    }
    
}